package com.sx.first.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;

import com.sx.first.model.Warehouse;

@Repository("warehouseDAO")
@Scope("prototype")
public class WarehouseDAO {
	private SessionFactory sessionFactory;

	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	public List<Warehouse> findAll() {
		@SuppressWarnings("unchecked")
		List<Warehouse> list = sessionFactory.getCurrentSession().createQuery("from Warehouse").list();
		return list;
	}

	public void save(Warehouse war) {
		sessionFactory.getCurrentSession().save(war);
	}

	public void delete(Warehouse war) {
		sessionFactory.getCurrentSession().delete(war);
	}

	public void update(Warehouse war) {
		sessionFactory.getCurrentSession().update(war);
	}

	public Warehouse findById(int warId) {
		return sessionFactory.getCurrentSession().get(Warehouse.class, warId);
	}

}
